package com.itdaan.portal.business.solr;

import java.util.ArrayList;
import java.util.List;

/**
 * solr分页对象
 * @author www.itdaan.com
 */
public class SolrPage {

	private int curPage = 1; // 当前页
	private int pageSize = 10; // 每页多少行
	private int totalRow; // 共多少行
	private int start;// 当前页起始行
	private int end;// 结束行
	private int totalPage; // 共多少页
	private List<Integer> pageIndexs;

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		if (curPage < 1) {
			curPage = 1;
		} else {
			start = pageSize * (curPage - 1);
		}
		end = start + pageSize > totalRow ? totalRow : start + pageSize;
		this.curPage = curPage;
	}

	public int getStart() {
		return start;
	}

	public int getEnd() {
		return end;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalRow() {
		return totalRow;
	}

	public void setTotalRow(int totalRow) {
		totalPage = (totalRow + pageSize - 1) / pageSize;
		this.totalRow = totalRow;
		if (totalPage < curPage) {
			curPage = totalPage;
			start = pageSize * (curPage - 1);
			end = totalRow;
		}
		end = start + pageSize > totalRow ? totalRow : start + pageSize;
		pageIndexs = new ArrayList<Integer>();
		int startPageIndex = 1;
		int endPageIndex = 1;
		if(curPage < 6){
			startPageIndex = 1;
		}else if(curPage >= 6 && totalPage-curPage > 4){//选择第6页作为当前页
			startPageIndex = curPage - 5;
		}else{
			startPageIndex = totalPage - 9;
			if(startPageIndex < 1) startPageIndex = 1;
		}
		endPageIndex = startPageIndex + 9;
		if(endPageIndex > totalPage) endPageIndex = totalPage;
		for(int i = startPageIndex;i <= endPageIndex;i++){
			pageIndexs.add(i);
		}
	}

	public int getTotalPage() {
		return this.totalPage;
	}

	public List<Integer> getPageIndexs() {
		return pageIndexs;
	}

	public void setPageIndexs(List<Integer> pageIndexs) {
		this.pageIndexs = pageIndexs;
	}
	
}
